package com.machine.filling.db;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.util.Log;

import com.machine.filling.db.greendao.AdModleDao;
import com.machine.filling.db.greendao.CardTempModleDao;
import com.machine.filling.db.greendao.ClientInfoModleDao;
import com.machine.filling.db.greendao.DaoMaster;
import com.machine.filling.db.greendao.ExceptionOrderModleDao;
import com.machine.filling.db.greendao.GunInfoModleDao;
import com.machine.filling.db.greendao.LocalOrderModleDao;
import com.machine.filling.db.greendao.TempOrderModleDao;
import com.machine.filling.db.greendao.TestModleDao;

import org.greenrobot.greendao.database.Database;

/**
 * 作者: SageTripp on
 * 时间: 2017/7/17
 * <p>
 * 描述:
 */
public class UpgradeHelper extends DaoMaster.OpenHelper {
    public UpgradeHelper(Context context, String name) {
        super(context, name);
    }

    public UpgradeHelper(Context context, String name, SQLiteDatabase.CursorFactory factory) {
        super(context, name, factory);
    }

    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
        super.onUpgrade(db, oldVersion, newVersion);
        Log.i("version", oldVersion + "---先前和更新之后的版本---" + newVersion);
        if (oldVersion < newVersion) {
            Log.i("version", oldVersion + "---先前和更新之后的版本---" + newVersion);
            MigrationHelper2.migrate(db,new MigrationHelper2.ReCreateAllTableListener() {

                        @Override
                        public void onCreateAllTables(Database db, boolean ifNotExists) {
                            DaoMaster.createAllTables(db, ifNotExists);
                        }

                        @Override
                        public void onDropAllTables(Database db, boolean ifExists) {
                            DaoMaster.dropAllTables(db, ifExists);
                        }
                    },
                    AdModleDao.class,
                    CardTempModleDao.class,
                    ClientInfoModleDao.class,
                    ExceptionOrderModleDao.class,
                    GunInfoModleDao.class,
                    LocalOrderModleDao.class,
                    TempOrderModleDao.class,
                    TestModleDao.class
            );
        }
    }

//,
//    AdModleDao.class,
//    CardTempModleDao.class,
//    ClientInfoModleDao.class,
//    ExceptionOrderModleDao.class,
//    GunInfoModleDao.class,
//    LocalOrderModleDao.class,
//    TempOrderModleDao.class,
//    TestModleDao.class
}
